home *** CD-ROM | disk | FTP | other *** search
- Path: news.tu-ilmenau.de!usenet
- From: Lars Krueger <ai108@rz.tu-ilmenau.de>
- Newsgroups: comp.lang.c++
- Subject: Is WATCOM 10.5 a broken compiler or am I stupid?
- Date: Thu, 28 Mar 1996 13:46:33 +0100
- Organization: Technische Universitaet Ilmenau
- Message-ID: <315A8A29.613B4EBA@rz.tu-ilmenau.de>
- NNTP-Posting-Host: scenic-03.rz.tu-ilmenau.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.13 i586)
-
- Hi.
-
- Yesterday I came across a strange error caused by following code:
-
- typedef struct cstringTEMP
- {
- char len;
- char data[255];
- public:
- cstringTEMP & operator=(char *);
- } cstring;
-
- char pchar2cstring(cstring &s, char *c)
- // Returns 1 for "c to long".
- // Returns 0 for success.
- {
- unsigned l=strlen(c);
- if( l>255)
- return 1;
- s.len=(char )l;
- memcpy(s.data,c,l);
- return 0;
- }
-
- cstring & cstring::operator=(char *s)
- {
- if( pchar2cstring(*this,s))
- len=0;
- return *this;
- }
-
-
-
-
- AND THIS IS THE CODE I TRIED TO USE:
-
- cstring cs="test";
-
-
- IT GAVE THIS ERROR-MESSAGE: (I CUT OUT THE LINE NUMBERS AND THE FILENAME
- TO SAVE SPACE.)
- Error! E400: (col 13) cannot convert right expression for initialization
- Note! N643: (col 13) cannot convert argument 1 defined in:
- Note! N630: (col 13) source conversion type is "char *"
- Note! N631: (col 13) target conversion type is "cstringTEMP const &"
-
- CHANGING THE LINE ABOVE TO:
-
- cstring cs;
- cs="test";
-
-
- AND THE ERROR WAS NOT LONGER THERE.
-
- And now are my questions
- 1.) Is this all my fault or a bug in the WATCOM C++ compiler.
- 2.) If it is my fault how do I have to change the declaration.
-
-
- Thanks in advance
-
- Lars
-